<?php

namespace Biz\Models\Site;

use Biz\Constants\Site\SiteNewsCategoryConstants;
use Biz\Constants\Site\SiteNewsConstants;
use Biz\Models\Model;
use Dimsav\Translatable\Translatable;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * SiteNews.
 *
 * @license [http://www.85do.com] [杭州永奥网络科技有限公司]
 * @copyright Copyright (c) 2018-2026 Hangzhou Yongao Technology Co., Ltd. All rights reserved.
 */
class SiteNews extends Model
{
    use SoftDeletes, Translatable;
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'site_news';

    /**
     * @var array
     */
    protected $fillable = [
        'site_id',
        'category_id',
        'status',
    ];

    /**
     * Translations.
     */
    public $translationModel      = SiteNewsTranslation::class;
    public $translatedAttributes  = ['title', 'summary', 'content'];
    public $translationForeignKey = 'news_id';

    /**
     * 获取分类.
     */
    public function category()
    {
        if($this->category_id === SiteNewsConstants::CATEGORY_DEFAULT){
            return null;
        }
        return $this->belongsTo(SiteNewsCategory::class, 'category_id', 'id');
    }
}
